package com.hd.service.generator.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hd.dao.BaseDao;
import com.hd.entity.generator.CodeGenerator;
import com.hd.service.generator.CodeGeneratorService;
import com.hd.util.result.PageInfo;

@Service("codeGeneratorService")
public class CodeGeneratorServiceImpl implements CodeGeneratorService {
    @Autowired
    private BaseDao<CodeGenerator,String>codeGeneratorDao;
    @Override
    public void save(CodeGenerator codeGenerator) {
    	codeGenerator.setId(UUID.randomUUID().toString());
    	codeGenerator.setCreateTime(new Date());
        codeGeneratorDao.save(codeGenerator);
    }
 
    @Override
    public void delete(String id) {
        codeGeneratorDao.delete(CodeGenerator.class,id);
    }

    @Override
    public void update(CodeGenerator codeGenerator) {
        codeGeneratorDao.update(codeGenerator);
    }

    @Override
    public void dataGrid(PageInfo info) {
        String hql="from CodeGenerator order by createTime desc";
        List<CodeGenerator> codeGeneratorList=codeGeneratorDao.findPage(hql,info.getNowpage(),info.getPagesize());
        info.setRows(codeGeneratorList);
        int total=codeGeneratorDao.find(hql).size();
        info.setTotal(total);
    }

    @Override
    public CodeGenerator getByTableName(String taleName) {
        String hql="from CodeGenerator where name=?";
        List<CodeGenerator>codeGenerators=codeGeneratorDao.find(hql,taleName);
        if(codeGenerators.size()>0){
            return codeGenerators.get(0);
        }else{
            return null;
        }
    }
}
